package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import lay.Map;
	import lay.Sence;
	import lay.StageChoose;
	import lay.UI;
	
	import myutils.LoadManager;
	
	public class GameStart extends Sprite
	{
		public static var gameStart:GameStart;
		private var log:TextField;
		private var logStr:String = "";
		private var map:Sprite;
		private var sence:Sprite;
		private var ui:Sprite;

		public static var WIDTH:int;
		public static var HEIGHT:int;
		
		public function GameStart()
		{
			gameStart = this;
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			WIDTH = stage.stageWidth;
			HEIGHT = stage.stageHeight;
			/**加载资源*/
			LoadManager.getInstance();
		}
		
		public function onLoadComplete():void
		{
			map = new Sprite();
			sence = new Sprite();
			ui = new Sprite();
			/**分层*/
			addChild(map);
			addChild(sence);
			addChild(ui);
			initLog();
			this.addEventListener(Event.ENTER_FRAME,onHeart);
			logMess("初始化完成");
			//choose stage
			ui.addChild(new StageChoose());
		}
		
		private function onHeart(e:Event):void
		{
			logMess("心在跳。。。")
		}
		
		public function initLog():void
		{
			log = new TextField();
			
			var format:TextFormat = new TextFormat();
			format.size = 30;
			
			log.width = stage.stageWidth /2 - 5;
			log.height = stage.stageHeight/2 - 5;
			log.x = stage.stageWidth /2;
			log.y = stage.stageHeight / 2;
			log.background = true;
			log.backgroundColor = 0x686868;
			log.defaultTextFormat = format;
			log.text = "LOG MESSAGE:\r";
			this.addChild(log);
		}
		
		public function logMess(str:String):void
		{	
			if(log == null)
			{	
				logStr += str+"\r\t";
			}else
			{
				if(logStr != "")
				{
					log.appendText(logStr+"\r\t");
					logStr = "";
				}
				log.appendText(str+"\r\t");
			}
		}
	}
}